package com.mateng.treasurechest.view.common.weight

import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.animation.LinearInterpolator
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.mateng.treasurechest.R

/**
 * Created by mateng on 2018/2/1.
 */
class NetProgressView : FrameLayout {

    private var ivProgress: ImageView? = null
    private var tvProgress: TextView? = null

    constructor(context: Context) : super(context) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        initView()
    }

    private fun initView() {
        LayoutInflater.from(context).inflate(R.layout.view_net_progress, this, true)
        ivProgress = findViewById(R.id.iv_progress)
        tvProgress = findViewById(R.id.tv_progress)
        defaultAnimation()
    }


    @SuppressLint("ObjectAnimatorBinding")
    private fun defaultAnimation() {
        val animation: ObjectAnimator = ObjectAnimator.ofFloat(ivProgress, "rotation", 0F, 360F)
        animation.duration = 1000
        animation.interpolator = LinearInterpolator()
        animation.repeatCount = -1
        animation.start()
    }

}